package com.diamond.smart.data.service.impl;

import com.diamond.smart.data.dao.VoltageDataDao;
import com.diamond.smart.data.vo.DuringDataVo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.diamond.common.utils.PageUtils;
import com.diamond.common.utils.Query;
import com.diamond.smart.data.entity.VoltageDataEntity;
import com.diamond.smart.data.service.VoltageDataService;


@Service("voltageDataService")
public class VoltageDataServiceImpl extends ServiceImpl<VoltageDataDao, VoltageDataEntity> implements VoltageDataService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<VoltageDataEntity> page = this.page(
                new Query<VoltageDataEntity>().getPage(params),
                new QueryWrapper<VoltageDataEntity>().orderByDesc("data_time")
        );
        return new PageUtils(page);
    }

    /**
     * 查询规定时间段的某个设备的数据
     *
     * @param vo
     * @return
     */
    @Override
    public List<VoltageDataEntity> getDuringDataByDeviceId(DuringDataVo vo) {
        return this.list(new QueryWrapper<VoltageDataEntity>().eq("device_id", vo.getDevice_id())
                .between("data_time", vo.getStartTime(), vo.getEndTime()));
    }

}